//
//  SyncFrequencyCell.m
//  Estate
//
//  Created by heyong on 2016/12/1.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "SyncFrequencyCell.h"

@implementation SyncFrequencyCell
- (UITextField *)timeText{
    if(!_timeText){
        _timeText=[[UITextField alloc]init];
    }
    return _timeText;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createCell];
    }
    return self;
}

- (void)createCell{
    
    self.selectionStyle=UITableViewCellSelectionStyleNone;
    UIView *headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 30)];
    headView.backgroundColor = [UIColor colorWithRed:0.96 green:0.97 blue:0.97 alpha:1.00];
    UILabel *lbe=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, 30)];
    lbe.text=@"同步判断频率";
    lbe.backgroundColor = [UIColor colorWithRed:0.96 green:0.97 blue:0.97 alpha:1.00];
    lbe.font=[UIFont systemFontOfSize:11*BIZ];
    lbe.textColor=UIColorFromRGB(0x787878);
    [headView addSubview:lbe];
    [self addSubview:headView];
    
    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(10, 30, 100, 44)];
    lab.text=@"频率";
    lab.textColor=UIColorFromRGB(0x787878);
    lab.font=[UIFont systemFontOfSize:14*BIZ];
    [self addSubview:lab];
    
    [self addSubview:self.timeText];
    self.timeText.frame=CGRectMake(DEF_SCREEN_WIDTH-100, 40, 50, 24);
    self.timeText.layer.borderWidth=1;
    self.timeText.font=[UIFont systemFontOfSize:14*BIZ];
    self.timeText.textAlignment=1;
    self.timeText.layer.borderColor=[UIColor colorWithRed:0.78 green:0.78 blue:0.79 alpha:1.00].CGColor;
    self.timeText.textColor=UIColorFromRGB(0x787878);
    self.timeText.layer.cornerRadius=4.;
    [self.timeText addTarget:self action:@selector(timeChange:) forControlEvents:UIControlEventEditingChanged];
    self.timeText.keyboardType=UIKeyboardTypeNumberPad;
    
    UILabel *lab1=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.timeText.frame)+5, 30, 50,44)];
    lab1.text=@"分钟";
    lab1.textColor=UIColorFromRGB(0x787878);
    lab1.font=[UIFont systemFontOfSize:14*BIZ];
    [self addSubview:lab1];
    
}

- (void)timeChange:(UITextField *)sender {
    if(self.timeChangeBlock){
        NSInteger num=[sender.text integerValue];
        if(num>=1440){
            sender.text=@"1440";
            num=1440;
        }
        self.timeText.text=[NSString stringWithFormat:@"%li",num];
        self.timeChangeBlock(sender.text);
    }
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"sync";
    SyncFrequencyCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[SyncFrequencyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
